package com.hujf.mapreduce.partitioner2;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author Hujf
 * @title: FlowBean
 * @date 2021/3/3017:01
 * @description: TODO
 *
 * 1.定义类实现writeable
 * 2.重写序列化和反序列化方法
 * 3.重写空参构造
 * 4.toString方法
 */

public class FlowBean implements Writable {

    //上行流量
    private long upFlow;

    public long getUpFlow() {
        return upFlow;
    }

    public void setUpFlow(long upFlow) {
        this.upFlow = upFlow;
    }

    public long getDownFlow() {
        return downFlow;
    }

    public void setDownFlow(long downFlow) {
        this.downFlow = downFlow;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal() {
        this.total = this.downFlow+this.upFlow;
    }

    //下行
    private long downFlow;
    //总
    private long total;


    //空参构造
    public FlowBean(){

    }
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(upFlow);
        out.writeLong(downFlow);
        out.writeLong(total);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.upFlow=in.readLong();
        this.downFlow=in.readLong();
        this.total=in.readLong();
    }

    @Override
    public String toString() {
        return
                 upFlow +
                "\t" + downFlow +
                "\t" + total ;
    }
}
